home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 6569 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.2 KB

  1. Path: gail.ripco.com!mambuhl
  2. From: mambuhl@ripco.com (Martin Ambuhl)
  3. Newsgroups: comp.lang.c
  4. Subject: newbie question concernin
  5. Date: 19 Feb 1996 18:53:53 GMT
  6. Organization: Ripco Communications, Inc.
  7. Message-ID: <4gah01$6cc@gail.ripco.com>
  8. NNTP-Posting-Host: foley.ripco.com
  9.  
  10. rblayney@extro.ucc.su.OZ.AU (Robert Blayney)
  11. in <rblayney.824643669@extro> asks:
  12.  
  13. >        I'm attempting to use the following function call
  14. >                fread(&result, sizeof(int), 16, fp);
  15.  
  16. If you have declared
  17.     int result[16];
  18. could change the above to:
  19.                  fread(result, sizeof(int), 16, fp);
  20.  
  21. >        Unfortunately when I attempt to print the contents of the result array
  22. >I obtain all zeros, where  result is declared:  int *result. I've tried success
  23. >ully
  24.  
  25. In which case there is no space allocated for result.  Try adding:
  26.     #include <stdlib.h>
  27.     #define RESLTS_NUM 16
  28.     /* .... */
  29.     int *result;
  30.     /* ... */
  31.         if (!(result = malloc(RESLTS_NUM * sizeof *result)))
  32.             /* error handling */;
  33.         fread(result, sizeof(int), 16, fp);
  34. at the appropriate place.
  35.  
  36.                                                                                  
  37. --
  38. * Martin Ambuhl       net: mambuhl@ripco.com
  39. * Chicago, IL (USA)    
  40.